﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NCalculator
{
    public partial class HistoryDialog : Form
    {
        #region Attributes
        private History _history;
        private DataTable _historyTable;
        private int _rowIndex;
        #endregion

        public HistoryDialog(History history)
        {
            InitializeComponent();
            _history = history;
            _historyTable = new DataTable();
        }

        private void simpleButtonOk_Click(object sender, EventArgs e)
        {
            if (_historyTable.Rows.Count > 0)
            {
                _rowIndex = dataGridViewHistory.SelectedRows[0].Index;
                this.Close();
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.Ignore;
            }
        }

        /// <summary>
        /// Get selected row index
        /// </summary>
        public int RowIndex
        {
            get { return _rowIndex; }
        }

        private void HistoryDialog_Load(object sender, EventArgs e)
        {
            _historyTable = new DataTable();
            _historyTable.Columns.Add("sn", typeof(int));
            _historyTable.Columns.Add("date", typeof(string)); 

            int i=1;
            foreach (HistoryContainer hc in _history.HistoryList)
            {
                DataRow row = _historyTable.NewRow();
                row[0] = i++;
                row[1] = hc.ToString();
                _historyTable.Rows.Add(row);
            }

            dataGridViewHistory.DataSource = _historyTable;
        }
    }
}
